#include "GainNode.h"
#include <qobject.h>

GainNode::GainNode()
    :m_in(new AbsIoNode(this, AbsIoNode::input))
    ,m_out(new AbsIoNode(this, AbsIoNode::output))
    ,m_gain(1)
{
    registerIoNode("input", m_in);
    registerIoNode("output", m_out);
    registerParam("gain", m_gain);
}

GainNode::~GainNode()
{
}

bool GainNode::run()
{
    qreal& in = (m_in->variable());
    qreal& out = (m_out->variable());
    out = in * m_gain;
    return true;
}

QString GainNode::lastErrorMsg()
{
    return QString();
}

QString GainNode::displayText()
{
    return nodeName();
}

QVariantMap GainNode::getParams()
{
    QVariantMap params;
    params.insert("gain", m_gain);
    return params;
}

void GainNode::setParams(QVariantMap paramsMap) { 
    m_gain = paramsMap.value("gain", 1.0).toDouble();
}

QString GainNode::nodeName()
{
    return QObject::tr("Gain");
}
